﻿using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Windows.Controls;
using Caliburn.Micro;
using Caliburn.Micro.Extensions;
using Caliburn.Micro.Logging;
using Coproject.Controls;
using Coproject.ViewModels.Interfaces;
using CoProjectModel;
using IdeaBlade.Application.Framework.Core.Authentication;

namespace CoProjectDF
{
    public class AppBootstrapper : FrameworkBootstrapper<IShell, CoProjectEntities>
    {
        static AppBootstrapper()
        {
            LogManager.GetLog = type => new LocalLogger(type);
        }

        public AppBootstrapper()
        {
            if (!Execute.InDesignMode)
            {
                //LogManager.GetLog = type => new LocalLogger(type);
                ILog log = LogManager.GetLog(typeof(AppBootstrapper));
                log.Info("AppBootstrapper constructor");
            }
        }

        protected override void InitializeCompositionBatch(CompositionBatch batch)
        {
            base.InitializeCompositionBatch(batch);

            // Inject the authentication service into the framework.
            batch.AddExportedValue<IAuthenticationService>(new AuthenticationService<CoProjectEntities>());
            InitializeConventions();
        }

        private void InitializeConventions()
        {
            ConventionManager.AddElementConvention<Controls.BusyIndicator>(Controls.BusyIndicator.IsBusyProperty, "IsBusy", "Loaded");
            ConventionManager.AddElementConvention<ExtendedTextBox>(TextBox.TextProperty, "Text", "EnterKeyDown");
        }
    }
}
